package com.example.myweb;

import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import java.io.File;

public class MainActivity extends AppCompatActivity {

    private WebView urlWebView;
    private Button mBt1;
    private Button mBt2;
    private Button mBt3;
    private Button mBt4;
    private WebView mWv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy( builder.build() );
        }
        setContentView(R.layout.activity_main);
        initView();
//        urlWebView.setVisibility(View.VISIBLE);
//
//        urlWebView.setWebViewClient(new AppWebViewClients());
//
//        urlWebView.getSettings().setJavaScriptEnabled(true);
//
//        urlWebView.getSettings().setUseWideViewPort(true);
//
//
//        urlWebView.loadUrl
//                ("http://view.officeapps.live.com/op/view.aspx?src=https://tidaizhe.cn/entLicense/123.ppt");


        mBt1.setOnClickListener(new View.OnClickListener() {
            /**
             * @param v
             */
            @Override
            public void onClick(View v) {
                String path = Environment.getExternalStorageDirectory()
                        .getAbsolutePath() + "/test.pdf";
                startActivity( OpenFileUtil.openFile(path));

//                Uri uri = Uri.parse(“http://www.google.com“); //浏览器
//                Uri uri =Uri.parse(“tel:1232333”); //拨号程序
//                Uri uri=Uri.parse(“geo:39.899533,116.036476”); //打开地图定位


//                Intent intent = new Intent();
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                intent.setAction(Intent.ACTION_VIEW);
////                Uri uri = Uri.parse("geo:39.899533,119.036476"); //打开地图定位
//
//                Uri uri = Uri.parse("http://www.baidu.com"); //浏览器
////                intent.setDataAndType(uri, "*/*");
//                intent.setData(uri);
//                startActivity(intent);
            }
        });
        mBt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent share_intent = new Intent();
                share_intent.setAction(Intent.ACTION_ALL_APPS);//设置分享行为
                share_intent.setType("text/plain");//设置分享内容的类型
                share_intent.putExtra(Intent.EXTRA_SUBJECT, "share");//添加分享内容标题
                share_intent.putExtra(Intent.EXTRA_TEXT, "share with you:" + "android");//添加分享内容
                //创建分享的Dialog
                share_intent = Intent.createChooser(share_intent, "share");
                startActivity(share_intent);

            }
        });
        mBt3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent share_intent = new Intent
                        (Intent.ACTION_CALL, Uri.parse("tel:" + "123"));

                startActivity(share_intent);
            }
        });
        mBt4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent share_intent = new Intent();
                share_intent.setAction(Intent.ACTION_CALL);
                startActivity(share_intent);
            }
        });
    }

    public class AppWebViewClients extends WebViewClient {

        @Override

        public boolean shouldOverrideUrlLoading(WebView view, String url) {

// TODO Auto-generated method stub

            view.loadUrl(url);

            return true;

        }

        @Override

        public void onPageFinished(WebView view, String url) {

// TODO Auto-generated method stub

            super.onPageFinished(view, url);

        }

    }

    private void initView() {
        urlWebView = (WebView) findViewById(R.id.wv);
        mBt1 = (Button) findViewById(R.id.bt_1);
        mBt2 = (Button) findViewById(R.id.bt_2);
        mBt3 = (Button) findViewById(R.id.bt_3);
        mBt4 = (Button) findViewById(R.id.bt_4);
        mWv = (WebView) findViewById(R.id.wv);
    }
}